package com.rainflowerstone.home;

import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.widget.QMUITabSegment;
import com.qmuiteam.qmuidemo.base.BaseFragment;
import com.rainflowerstone.R;
import com.rainflowerstone.adapter.RainFlowerStoneHomeAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ Author     ：lwc
 * @ Date       ：Created in 10:34 2018/12/26
 * @ Description：${description}
 * @ Modified By：
 * @Version: $version$
 */
public class RainFlowerStoneHomeFragment extends BaseFragment {

    private final static String TAG = RainFlowerStoneHomeFragment.class.getSimpleName();
    @BindView(R.id.pager)
    ViewPager mViewPager;
    @BindView(R.id.tabs)
    QMUITabSegment mTabSegment;

    private RainFlowerStoneHomeAdapter mRainFlowerStoneHomeAdapter;

    @Override
    protected View onCreateView() {
        FrameLayout layout = (FrameLayout) LayoutInflater.from(getActivity()).inflate(R.layout.rain_flower_stone_fragment_home, null);
        ButterKnife.bind(this, layout);
        initTabs();
        initPagers();
        return layout;
    }

    private void initTabs() {
        int normalColor = QMUIResHelper.getAttrColor(getActivity(), R.attr.qmui_config_color_gray_6);
        int selectColor = QMUIResHelper.getAttrColor(getActivity(), R.attr.qmui_config_color_blue);
        mTabSegment.setDefaultNormalColor(normalColor);
        mTabSegment.setDefaultSelectedColor(selectColor);
        mTabSegment.setDefaultTabIconPosition(QMUITabSegment.ICON_POSITION_TOP);
//        mTabSegment.setMode(QMUITabSegment.MODE_SCROLLABLE);//MODE_SCROLLABLE 自适应宽度+滚动
//        mTabSegment.setItemSpaceInScrollMode(QMUIDisplayHelper.dp2px(getActivity(), 16));
        QMUITabSegment.Tab component = new QMUITabSegment.Tab(
                ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component),
                ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_component_selected),
                "首页", false,true
        );

        QMUITabSegment.Tab about = new QMUITabSegment.Tab(
                ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util),
                ContextCompat.getDrawable(getContext(), R.mipmap.icon_tabbar_util_selected),
                "关于", false,true
        );
        about.showSignCountView(getContext(),2);
        mTabSegment.addTab(component).addTab(about);
    }

    private void initPagers(){
        mRainFlowerStoneHomeAdapter = new RainFlowerStoneHomeAdapter(getActivity().getSupportFragmentManager());
        mViewPager.setOffscreenPageLimit(1);
        mViewPager.setAdapter(mRainFlowerStoneHomeAdapter);
        mTabSegment.setupWithViewPager(mViewPager,false);
    }
    /**
     * 首页禁止拖动,否则报错
     * @return
     */
    @Override
    protected boolean canDragBack() {
        return false;
    }

}
